import React, {Component} from 'react';
import {getStudents, getCars} from "./api";

/**
 * 单代理配置 package.json
 * "proxy": "http://localhost:5001"
 */
class App extends Component {

  getStudents = () => {
    // fetch('/api1/students')
    //   .then(res => res.json())
    //   .then(data => console.log(data));
    getStudents().then(data => console.log(data));
  };

  getCars = () => {
    // fetch('/api2/cars')
    //   .then(res => res.json())
    //   .then(data => console.log(data));
    getCars().then(data => console.log(data))
  };

  render() {
    return (
      <React.Fragment>
        <h2>配置代理</h2>
        <button onClick={this.getStudents}>getStudents</button>
        <button onClick={this.getCars}>getCars</button>
      </React.Fragment>
    );
  }
}

export default App;